//
//  YQOrderDetailsHeaderView.m
//  MuYing
//
//  Created by tbb on 2019/8/1.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQRefundOrderDetailsHeaderView.h"
#import "Calculagraph.h"
#import "YQGoodsOrderDetailsModel.h"
@interface  YQRefundOrderDetailsHeaderView ()
@property (nonatomic,strong) Calculagraph *codeTimer;
@end

@implementation YQRefundOrderDetailsHeaderView

- (void)layoutSubviews {
    [super layoutSubviews];
    self.topBgView.backgroundColor = kAPPThemeColor;
    
    self.locationView.backgroundColor = UIColor.whiteColor;
    self.locationView.layer.cornerRadius=15;
    self.locationView.layer.shadowColor=[UIColor blackColor].CGColor;
    self.locationView.layer.shadowOffset=CGSizeMake(0, 0);
    self.locationView.layer.shadowOpacity=0.5;
    self.locationView.layer.shadowRadius=5;
    self.stateLb.text = @"";

}
/*
 *售后状态，1是已提交申请待补充物流（需管理员同意），2是已提交待审核，3是管理员同意退货，4管理员同意退款，5是管理员审核拒绝，6是用户已取消
*/
-(void)setNewsOrderModel:(YQGoodsOrderDetailsModel *)newsOrderModel {
    _newsOrderModel = newsOrderModel;
    self.timeLb.text = @"";
    switch (newsOrderModel.aftersaleStatus) {
        case 101:
            self.stateLb.text = kYQLS(@"等待买家付款");
            break;
        case 102:
        case 103:
        case 202:
            self.stateLb.text = kYQLS(@"交易失败");
            break;
        case 201:
            self.stateLb.text = kYQLS(@"已付款，等待卖家确认");
            break;
        case 301:
            self.stateLb.text = kYQLS(@"卖家已确认、请使用");
            break;
        case 302:
        case 303:
            self.stateLb.text = kYQLS(@"待评价");
            break;
        
        default:
            break;
    }
}

-(void)setOrderDetailsModel:(YQGoodsOrderDetailsModel *)orderDetailsModel {
    _orderDetailsModel = orderDetailsModel;
    
    /*
     self.headerView.stateLb.text = @"确认收货";
     self.headerView.timeLb.text = @"剩余: 05小时57小时";
     self.headerView.nameLb.text = @"李晓冬";
     self.headerView.phoneLb.text = @"17727956732";
     self.headerView.locationLb.text = @"地址 : 广东省深圳市南山区蛇口街道创业一号C栋";
     */
    self.nameLb.text = orderDetailsModel.userName;
    self.phoneLb.text = orderDetailsModel.userPhone;
    self.locationLb.text = orderDetailsModel.userAddress;
    self.timeLb.hidden = YES;
    switch (self.orderDetailsModel.aftersaleStatus) {
        case -1:
            self.stateLb.text = kYQLS(@"不可申请");
            break;
        case 0:
            self.stateLb.text = kYQLS(@"可申请");
            break;
        case 1:
            self.stateLb.text = kYQLS(@"申请退款");
            break;
        case 2:
            self.stateLb.text = kYQLS(@"申请退货退款");
            break;
        case 3:
            self.stateLb.text = kYQLS(@"管理员同意退款");
            break;
        case 4:
            self.stateLb.text = kYQLS(@"管理员同意退货退款，待补充物流");
            break;
        case 5:
            self.stateLb.text = kYQLS(@"用户已补充物流");
            break;
        case 6:
            self.stateLb.text = kYQLS(@"管理员拒绝");
            break;
        case 7:
            self.stateLb.text = kYQLS(@"用户撤销");
            break;
        case 8:
            self.stateLb.text = kYQLS(@"完成售后");
            break;
        default:
            break;
    }
}

- (void)setRefundModel:(YQRefundDetailModel *)refundModel
{
    _refundModel = refundModel;
    self.nameLb.hidden = YES;
       self.phoneLb.hidden = YES;
       self.locationLb.hidden = YES;
       self.timeLb.hidden = YES;
    if ([refundModel.status isEqualToString:@"-1"]) {
        self.stateLb.text = kYQLS(@"不可申请");
    }else if([refundModel.status isEqualToString:@"0"]){
        self.stateLb.text = kYQLS(@"可申请");
    }else if ([refundModel.status isEqualToString:@"1"]){
        self.stateLb.text = kYQLS(@"申请退款");
    }else if ([refundModel.status isEqualToString:@"2"]){
        self.stateLb.text = kYQLS(@"申请退货退款");
    }else if ([refundModel.status isEqualToString:@"3"]){
        self.stateLb.text = kYQLS(@"管理员同意退款");
    }else if ([refundModel.status isEqualToString:@"4"]){
        self.stateLb.text = kYQLS(@"管理员同意退货退款，待补充物流");
    }else if ([refundModel.status isEqualToString:@"5"]){
        self.stateLb.text = kYQLS(@"用户已补充物流");
    }else if ([refundModel.status isEqualToString:@"6"]){
        self.stateLb.text = kYQLS(@"管理员拒绝");
    }else if ([refundModel.status isEqualToString:@"7"]){
        self.stateLb.text = kYQLS(@"用户撤销");
    }else if ([refundModel.status isEqualToString:@"8"]){
        self.stateLb.text = kYQLS(@"完成售后");
    }
}


#pragma mark -- 积分商城的订单
- (void)setModel:(YQPOrderInfoModel *)model
{
    _model = model;
    if ([model.orderStatus isEqualToString:@"0"]) {
        self.stateLb.text = kYQLS(@"订单待付款");

    }else if ([model.orderStatus isEqualToString:@"1"]) {
        self.stateLb.text = kYQLS(@"买家已付款，等待卖家发货");

    }else if ([model.orderStatus isEqualToString:@"2"]) {
        self.stateLb.text = kYQLS(@"订单已发货");

    }else if ([model.orderStatus isEqualToString:@"3"]) {
        self.stateLb.text = kYQLS(@"订单已完成");

    }else if ([model.orderStatus isEqualToString:@"4"]) {
        self.stateLb.text = kYQLS(@"订单已关闭");

    }
    self.timeLb.text = @"剩余: 05小时57小时";
    self.nameLb.text = model.receiverName;
    self.phoneLb.text = model.receiverPhone;
    self.locationLb.text = [NSString stringWithFormat:@"%@ : %@%@%@",kYQLS(@"地址"),model.receiverProvince,model.receiverCity,model.receiverDetailAddress];
}

- (Calculagraph *)codeTimer {
    if (!_codeTimer) {
        _codeTimer = [[Calculagraph alloc] init];
        [_codeTimer addObserver:self forKeyPath:@"time" options:NSKeyValueObservingOptionNew context:nil];
    }
    return _codeTimer;
}
- (void)dealloc {
    [self.codeTimer removeObserver:self forKeyPath:@"time"];
    self.codeTimer = nil;
}

@end

